package com.example.Servlet;

import com.example.dao.impl.OperationDaoImpl;
import com.google.gson.Gson;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

public class Operation extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter out = resp.getWriter();

        Gson gson = new Gson();
        List<com.example.Pojo.Operation> operations = new OperationDaoImpl().findAllOperations();
        if (operations != null && operations.size() > 0){
            System.out.println("记录查找成功");
            String json = gson.toJson(operations);
            out.println(json);
        }else {
            System.out.println("记录查找失败");
            out.print("未找到任何记录!");
        }
    }
}
